/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package baitap;

import java.util.Scanner;

/**
 *
 * @author Nhim
 */
public class Bai2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt(), b = input.nextInt();
        System.out.println(Ucln(a,b));
    }
    
    public static int Ucln(int a, int b){
        int m, n;
        if(a > b){
            m = a; n = b;
        }
        else{
            m = b; n = a;
        }
        while(n > 0){
            int tg = m%n;
            m = n;
            n = tg;
        }
        return m;
    }
}
